home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / modules / scsidev43.asm < prev    next >
Assembly Source File  |  2000-02-16  |  6KB  |  304 lines

  1. ; FILE: Source:modules/SCSIDEV43.ASM          REV: 7 --- Install V43 scsi.device
  2.  
  3. ;
  4. ; Plant V43 scsi.device -Module
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This patch module will install V43 scsi.device replacing one inside
  7. ; kickstart. It will also disable beta message of the scsi.device :)
  8. ;
  9. ; Device will be loaded from file "devs:scsi43.device".
  10. ;
  11. ; This module can't install A4000T_scsidisk 43.34 because it uses
  12. ; several hunks. Use V44 SetPatch + AmigaOS ROM Update to load it
  13. ; instead.
  14. ;
  15. ; This module has been tested with following scsi.device (a300.ld.strip)
  16. ;  versions:
  17. ;
  18. ;    43.11 (3.9.96)    Works fine for me.
  19. ;    43.17 (12.5.97)    Works, but doesn't recognize my drives! :(
  20. ;    43.18 (15.6.97)    Works fine.
  21. ;    43.23 (7.11.97)    Works fine.
  22. ;    43.24 (9.11.98)    Works fine.
  23. ;    43.34 (21.12.99)   Works fine.
  24. ;
  25. ; Written by Harry Sintonen.
  26. ; This source code is Public Domain.
  27. ;
  28.  
  29.     incdir    "include:"        ; Some required...
  30.     include    "exec/types.i"
  31.     include    "exec/libraries.i"
  32.     include    "blizkickmodule.i"
  33.  
  34. SCSI_MAXSIZE    EQU    17352+4096
  35.  
  36. _LVOCopyMem    EQU    -$270
  37.  
  38. _LVOIoErr    EQU    -$84
  39. _LVOLoadSeg    EQU    -$96
  40. _LVOUnLoadSeg    EQU    -$9C
  41. _LVOSetIoErr    EQU    -$1CE
  42.  
  43. call    MACRO
  44.     jsr    (_LVO\1,a6)
  45.     ENDM
  46.  
  47.     SECTION    PATCH,CODE
  48. _DUMMY_LABEL
  49.     BK_PTC
  50.  
  51. ; Code is run with following incoming parameters:
  52. ;
  53. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  54. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  55. ; d0=ROM lenght in bytes    eg. $00080000
  56. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  57. ;    CALL: jsr (a2)
  58. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  59. ;     OUT: d0=ptr to resident (buf) or NULL
  60. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  61. ;    CALL: jsr (a3)
  62. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  63. ;     OUT: d0=success
  64. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  65. ;    CALL: jsr (a4)
  66. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  67. ;     OUT: -
  68. ; d6=dosbase, a6=execbase
  69. ;
  70. ; Code should return:
  71. ;
  72. ; d0=true if succeeded, false if failed.
  73. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  74.  
  75.  
  76. ; NOTE: Kickstart *is* 2.0+
  77.  
  78.     cmp.w    #39,($C,a0)        ; Requires KS ROM V3.1+
  79.     bhs.b    .go
  80.     moveq    #0,d0
  81.     rts
  82.  
  83. .go    movem.l    d0/a0-a1,-(sp)
  84.     moveq    #0,d7
  85.  
  86.     lea    (_scsiname,pc),a1    ; _FindResident
  87.     jsr    (a2)
  88.     tst.l    d0
  89.     beq    .xit
  90.     move.l    d0,a5            ; a5=scsi.device resident
  91.  
  92.     moveq    #1,d7
  93.     move.l    (RT_IDSTRING,a5),a0
  94.     sub.l    (2*4,sp),a0        ;[a1]
  95.     add.l    (1*4,sp),a0        ;[a0]
  96.     lea    (_hdiname,pc),a1
  97.     moveq    #12-1,d1        ; 'IDE_scsidisk'
  98. .cmp    move.b    (a0)+,d0
  99.     cmp.b    (a1)+,d0
  100.     dbne    d1,.cmp
  101.     tst.w    d1            ; Test if already installed
  102.     bmi    .xit
  103.  
  104.     moveq    #0,d7
  105.     moveq    #-1,d4            ; IoErr=-1 (default)
  106.     exg    d6,a6
  107.     lea    (_hddname,pc),a0
  108.     move.l    a0,d1
  109.     call    LoadSeg
  110.     move.l    d0,d5
  111.     beq    .exit
  112.  
  113.     move.l    d5,a2
  114.     add.l    a2,a2
  115.     add.l    a2,a2
  116.     tst.l    (a2)+            ; Requires single hunk exe!
  117.     bne    .baddie            ; a2=hunk start
  118.  
  119.     moveq    #127,d0            ; Find resident:
  120.     move.w    #$4AFC,d1
  121.     move.l    a2,a0
  122. .findrt    cmp.w    (a0)+,d1
  123.     dbeq    d0,.findrt
  124.     tst.w    d0
  125.     bmi    .baddie
  126.     subq.l    #2,a0
  127.     cmp.l    (RT_MATCHTAG,a0),a0
  128.     bne.b    .findrt
  129.  
  130.     tst.b    (RT_FLAGS,a0)        ; Allow no RTF_AUTOINIT
  131.     bmi    .baddie
  132.  
  133.     ; a0=residenttag (loadsed), a2=1st seg start
  134.     bsr    makepcrel
  135.  
  136.     ; a0=residenttag (loadsed), a2=1st seg start
  137.     bsr    disablebeta
  138.  
  139.     lea    (_buf,pc),a1
  140.     move.l    #BKMODULE_ID,(a1)+    ; bkm_ID
  141.     move.l    #(0)<<16!RTC_MATCHWORD,(a1)+ ; bkm_Flags RT_MATCHWORD
  142.     clr.l    (a1)+            ; RT_MATCHTAG
  143.     moveq    #RT_SIZE,d0
  144.     add.l    (RT_ENDSKIP,a0),d0
  145.     sub.l    a2,d0
  146.     cmp.l    #SCSI_MAXSIZE,d0    ; Too big?
  147.     bhi.b    .baddie            ; It is quit!
  148.  
  149.     move.l    d0,(a1)+        ; RT_ENDSKIP
  150.     move.l    (RT_FLAGS,a0),(a1)+    ; RT_FLAGS,RT_VERSION,RT_TYPE,RT_PRI
  151.     moveq    #RT_SIZE,d0
  152.     add.l    (RT_NAME,a0),d0
  153.     sub.l    a2,d0
  154.     move.l    d0,(a1)+        ; RT_NAME
  155.     moveq    #RT_SIZE,d0
  156.     add.l    (RT_IDSTRING,a0),d0
  157.     sub.l    a2,d0
  158.     move.l    d0,(a1)+        ; RT_IDSTRING
  159.     moveq    #RT_SIZE,d0
  160.     add.l    (RT_INIT,a0),d0
  161.     sub.l    a2,d0
  162.     move.l    d0,(a1)+        ; RT_INIT
  163.  
  164.     clr.w    (a0)            ; Kill old RT_MATCHWORD
  165.  
  166.     movem.l    a0-a1,-(sp)
  167.     move.l    (RT_ENDSKIP,a0),d0
  168.     sub.l    a2,d0
  169.     move.l    a2,a0
  170.     exg    d6,a6            ;ex6--
  171.     call    CopyMem
  172.     movem.l    (sp)+,a0-a1
  173.  
  174. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  175.     movem.l    (sp),d0/a0        ;[d0][a0]
  176.     lea    (_buf,pc),a1
  177.  
  178.     move.w    ($C,a0),d1        ; Kludge fix kick version to scsi version...
  179.     move.b    (bkm_ResTag+RT_VERSION,a1),($C+1,a0)
  180.     jsr    (a3)            ; _InstallModule
  181.     move.w    d1,($C,a0)        ; Restore kick version
  182.     exg    d6,a6            ;--ex6
  183.     move.l    d0,d7            ; set success flag
  184.  
  185.     call    IoErr
  186.     move.l    d0,d4
  187.  
  188.     lea    (_nullstr,pc),a2
  189.     tst.l    d7
  190.     beq.b    .bskip2
  191.  
  192. ;debug    clr.w    (a5)            ; Kill ROM scsi.device ROMTag :)
  193.  
  194. .baddie    lea    (_error2,pc),a2
  195. .bskip2    move.l    d5,d1
  196.     call    UnLoadSeg
  197.     bra.b    .bskip
  198.  
  199. .exit    lea    (_error1,pc),a2        ; a0=fmt
  200. .bskip
  201.     exg    d6,a6
  202.     move.l    d7,d0            ; Valid counter?
  203.     bne.b    .xit
  204.     move.l    a2,a0            ; a0=fmt
  205.     pea    (_hddname,pc)
  206.     move.l    sp,a1            ; a1=array
  207.     jsr    (a4)            ; Call _Printf
  208.     addq.l    #4,sp
  209.  
  210.     move.l    d4,d1
  211.     addq.l    #1,d4
  212.     beq.b    .skip
  213.     exg    d6,a6
  214.     call    SetIoErr
  215. .skip
  216.     moveq    #0,d0            ; Return fail
  217. .xit    lea    (3*4,sp),sp
  218.     rts
  219.  
  220.  
  221.  
  222. ; a0=residenttag (loadsed), a2=1st seg start
  223. makepcrel    move.l    a0,-(sp)
  224.     move.l    (RT_ENDSKIP,a0),d3    ;d3=max
  225.     move.l    a2,d2            ;d2=min
  226.     move.l    a2,a0
  227.  
  228. .mpcloop    addq.l    #2,a0
  229.     cmp.l    a0,d3
  230.     bls.b    .mpcldone
  231.  
  232.     move.l    (a0),d0
  233.     cmp.l    d0,d2
  234.     bhi.b    .mpcloop
  235.     cmp.l    d0,d3
  236.     bls.b    .mpcloop
  237.  
  238.     move.l    (-2,a0),d1
  239.  
  240.     cmp.l    #$4EB90000,d1        ; jsr abs.l -> jsr asb(pc); nop
  241.     bne.b    .mpcs0
  242.     sub.l    a0,d0
  243.     move.w    #$4EBA,(-2,a0)
  244.     move.w    d0,(a0)+
  245.     move.w    #$2048,(a0)        ; move.l a0,a0 (nop)
  246.     ;bra.b    .mpcloop
  247. .mpcs0
  248.     bra.b    .mpcloop
  249. .mpcldone
  250.     move.l    (sp)+,a0
  251.     rts
  252.  
  253.  
  254. ; a0=residenttag (loadsed), a2=1st seg start
  255. disablebeta    move.l    a0,-(sp)
  256.     moveq    #-(5*4),d3
  257.     add.l    (RT_ENDSKIP,a0),d3    ;d3=max
  258.     move.l    (RT_INIT,a0),d2        ;d2=min
  259.     move.l    d2,a0
  260.  
  261.     move.l    #$48E7C0C0,d1        ;preload
  262.  
  263. .loop    addq.l    #2,a0
  264.     cmp.l    a0,d3
  265.     bls.b    .done
  266.  
  267.     cmp.l    (a0),d1
  268.     bne.b    .loop
  269.     cmp.w    #$206D,(4,a0)
  270.     bne.b    .loop
  271.     tst.b    (6,a0)
  272.     bne.b    .loop
  273.     move.l    (8,a0),d0
  274.     and.l    #$FFFFFFF0,d0
  275.     cmp.l    #$224E7000,d0
  276.     bne.b    .loop
  277.     cmp.w    #$6100,(12,a0)
  278.     bne.b    .loop
  279.     cmp.l    #$4CDF0303,(16,a0)
  280.     bne.b    .loop
  281.  
  282.     move.w    #$6012,(a0)        ;skip it!
  283. .done
  284.     move.l    (sp)+,a0
  285.     rts
  286.  
  287.  
  288. _scsiname    dc.b    'scsi.device',0
  289. _hdiname    dc.b    'IDE_scsidisk',0
  290. _hddname    dc.b    'devs:scsi43.device',0
  291.  
  292. _error1    dc.b    'Couldn''t load "%s"!',10,0
  293. _error2    dc.b    'Couldn''t utilize this %s version!',10,0
  294. _nullstr    EQU    *-1
  295.  
  296.  
  297.     CNOP    0,4
  298. _buf    ds.b    SCSI_MAXSIZE+bkm_ResTag+RT_SIZE
  299.  
  300.  
  301.     SECTION    VERSION,DATA
  302.  
  303.     dc.b    '$VER: SCSIDEV43_PATCH 1.3 (8.1.00)',0
  304.